package com.monkeyboy.spring.config;

import com.monkeyboy.spring.model.User;
import com.monkeyboy.spring.myimport.TestImport;
import com.monkeyboy.spring.service.A;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Service;

/**
 * @Author Gavin
 * @date 2020.06.22 10:55
 */
@Configuration
@ComponentScan(basePackages = "com.monkeyboy.spring")
//@Import(MyImport.class)
//@EnableAspectJAutoProxy
@Import(TestImport.class)
public class AppConfig extends A {
	public static void main(String[] args) {
		AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
		System.out.println("=====================================");
		System.out.println(annotationConfigApplicationContext.getBean("z"));
		System.out.println(annotationConfigApplicationContext.getBean("x"));
//		annotationConfigApplicationContext.register(AppConfig.class);
//		annotationConfigApplicationContext.scan("com.monkeyboy.spring");
//		annotationConfigApplicationContext.refresh();
//		User testImport= (User) annotationConfigApplicationContext.getBean("user");
//		System.out.println(testImport);

//		annotationConfigApplicationContext.setAllowCircularReferences(false);
//		A a = (A) annotationConfigApplicationContext.getBean("a");
//		annotationConfigApplicationContext.addBeanFactoryPostProcessor();
//		System.out.println("-------------");
//		a.getB();
//		annotationConfigApplicationContext.getBean("b");
//		System.out.println(annotationConfigApplicationContext.getBean("a"));


		/**
		 * 扫描自定义注解
		 */
//		System.out.println("------------");
//		//自定义的scanner需要传入一个registry工厂类，当扫描出来bd后就放入到这个registry里面，这儿的registry就是上面的annotationConfigApplicationContext
//		//这样通过自定义的扫描器扫描出来的bd也会放入到ApplicationContext里面
//		CustomerScanner customerScanner=new CustomerScanner(annotationConfigApplicationContext);
//		customerScanner.addIncludeFilter(new AnnotationTypeFilter(CustomAnno.class));
//		int scan = customerScanner.scan("com.monkeyboy");
////		System.out.println(scan);
//		Test test = (Test) annotationConfigApplicationContext.getBean("test");
//		test.say();

		//测试下面的内部内解析情况
//		Object e = annotationConfigApplicationContext.getBean("e");
//		System.out.println(e);
//		Object s = annotationConfigApplicationContext.getBean("s");
//		System.out.println(s);
//		Object h = annotationConfigApplicationContext.getBean("h");
//		System.out.println(h);
//		Object m=annotationConfigApplicationContext.getBean("m");
//		System.out.println(m);//不会被实例化
	}


	//	class M {
//		@Bean
//		public E e() {
//			return new E();
//		}
//	}
//	@Configuration("s")
//	class S {
//
//	}
//
//	@Component("h")
//	class H {
//		public H(){
//			System.out.println("h被初始化了");
//		}
//	}
	public static class L implements InitializingBean {

		@Override
		public void afterPropertiesSet() throws Exception {
			System.out.println("L---被初始化了");
		}
	}

	@org.springframework.context.annotation.Configuration
	@Import(AppConfig.L.class)
	public static class Z {
	}
}